<html>
<head><meta charset="utf-8"><title>Edition-dependent type aliases · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html">Edition-dependent type aliases</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227650138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227650138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227650138">(Feb 24 2021 at 18:41)</a>:</h4>
<p>Turns out it's pretty easy to make the same path refer to different types in different editions (e.g. to make std::ops::Range be a Copy type on edition 2021, and move the iterator/non-copy one to std::iter::Range, cc <span class="user-mention" data-user-id="243558">@Steven Fackler</span>): <a href="https://github.com/rust-lang/rust/pull/82489">https://github.com/rust-lang/rust/pull/82489</a></p>
<p>Not saying we should do this, but looks like it's possible with a pretty small change.</p>



<a name="227650921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227650921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227650921">(Feb 24 2021 at 18:46)</a>:</h4>
<p>oh nice! Yeah, I think the question for that bit of the proposal is more "should we" rather than "can we". I'm worried about what rustdoc would do in particular</p>



<a name="227651091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227651091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227651091">(Feb 24 2021 at 18:47)</a>:</h4>
<p>yeah, it'd need to understand this attribute and document it in some way. but eddyb's idea was to only allow this on type aliases, and not as some kind of cfg() thing. that makes it a lot easier for both rustdoc and rustc.</p>



<a name="227657214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227657214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227657214">(Feb 24 2021 at 19:27)</a>:</h4>
<p>I'm not sure how that is better for rustdoc</p>



<a name="227658952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227658952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227658952">(Feb 24 2021 at 19:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases/near/227657214">said</a>:</p>
<blockquote>
<p>I'm not sure how that is better for rustdoc</p>
</blockquote>
<p>guessing its because the docs get associated with the alias rather than the internal options</p>



<a name="227660493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227660493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227660493">(Feb 24 2021 at 19:50)</a>:</h4>
<p>because the items it resolves to can still have their own place/path/page, and the alias can be a simple page linking them both</p>



<a name="227678323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227678323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227678323">(Feb 24 2021 at 21:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases/near/227657214">said</a>:</p>
<blockquote>
<p>I'm not sure how that is better for rustdoc</p>
</blockquote>
<p>even if rustdoc handles it badly now, it makes it <em>possible</em> for rustdoc to tell the difference. Rustdoc doesn't see <code>cfg</code> at <em>all</em> <a href="https://github.com/rust-lang/rust/issues/1998">https://github.com/rust-lang/rust/issues/1998</a></p>



<a name="227679590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/227679590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#227679590">(Feb 24 2021 at 21:54)</a>:</h4>
<p>oh I'm well aware of how not-seeing-cfg rustdoc is, as all the earlier versions of <code>fermium</code> can silently show</p>



<a name="228335168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335168">(Mar 02 2021 at 00:53)</a>:</h4>
<p>So, if I have a crate D which is a dependency of crate A and D exports <code>std::ops::Range</code> in it's public interface. If crate D migrates to the 2021 edition, the type in it's interface can't change, since upgrading editions isn't supposed to be a semver breaking change, right?</p>



<a name="228335311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335311">(Mar 02 2021 at 00:55)</a>:</h4>
<p><code>std::ops::Range</code> will be the same in both editions. <code>0..1</code> will be a different type depending on the edition (something like <code>std::ops::Range2021</code>)</p>



<a name="228335460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335460">(Mar 02 2021 at 00:56)</a>:</h4>
<p>Note:  "Turns out it's pretty easy to make the same path refer to different types in different editions" suggests that there exists a path which has different types, even if I misunderstood and <code>std::ops::Range</code> isn't the proposed type which changes.</p>



<a name="228335478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335478">(Mar 02 2021 at 00:57)</a>:</h4>
<p>that seems really weird to me</p>



<a name="228335511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335511">(Mar 02 2021 at 00:57)</a>:</h4>
<p>oh huh it's a new compiler built-in</p>



<a name="228335514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335514">(Mar 02 2021 at 00:57)</a>:</h4>
<p>I guess that works too</p>



<a name="228335548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335548">(Mar 02 2021 at 00:58)</a>:</h4>
<p>This isn't about <code>0..1</code> returning a different type, it's about what type is referred to by a given path.</p>



<a name="228335668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228335668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228335668">(Mar 02 2021 at 00:59)</a>:</h4>
<p>As far as I can tell, exporting <code>std::ops::Range</code> is allowed and upgrading a crate to a new edition can't impact semver compatibility, so that suggests that all paths need to refer to consistent types across editions?</p>



<a name="228336439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228336439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228336439">(Mar 02 2021 at 01:06)</a>:</h4>
<p>The <code>cargo fix</code> for moving to 2021 would change it to use <code>Range2018</code> rather than the type alias <code>Range</code>.</p>
<p>Then calling it would require <code>(0..10).into_iter()</code> for code in 2021, but code in 2018 would still be able to call it with just <code>0..10</code>.</p>



<a name="228338004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228338004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228338004">(Mar 02 2021 at 01:23)</a>:</h4>
<p>So, crate A would have to change it's interface to export <code>std::ops::Range2018</code> in order to maintain semver after upgrading editions?</p>



<a name="228340192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228340192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228340192">(Mar 02 2021 at 01:50)</a>:</h4>
<p>So if crate A stayed on 2018, it'd still say <code>Range</code>, which would be <code>Range2018</code>.  If it wanted to upgrade editions, it'd also have that <code>Range</code>-&gt;<code>Range2018</code> rename that D had.</p>
<p>But the cross-edition mixes would all still work.</p>



<a name="228341647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228341647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ahmed Charles <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228341647">(Mar 02 2021 at 02:08)</a>:</h4>
<p>It seems like that would make using <code>cargo fix</code> really important. I hope it's documented well, cause simply changing the <code>Cargo.toml</code> to be the new edition would silently break a crate where this was the only issue.</p>



<a name="228348639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228348639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228348639">(Mar 02 2021 at 03:46)</a>:</h4>
<p>See <a href="https://doc.rust-lang.org/nightly/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html">https://doc.rust-lang.org/nightly/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html</a> -- it's fairly normal that just changing the number wouldn't be sufficient.</p>



<a name="228356497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228356497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228356497">(Mar 02 2021 at 05:35)</a>:</h4>
<p>I think the current version should be called std::iter::Range on all editions. (not Range2018 or Range1 or something)</p>



<a name="228356909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228356909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228356909">(Mar 02 2021 at 05:42)</a>:</h4>
<p>I agree that <code>Range</code> should be available in all editions.  I was just expecting that the specific names would also be available for migration purposes.  (Either rename to Range2018, upgrade editions, then rewrite to Range; or rewrite to Range2021, upgrade editions, then rename to Range.)</p>



<a name="228377119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228377119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228377119">(Mar 02 2021 at 09:16)</a>:</h4>
<p>Yes, and i'm suggesting the specific name for the <code>Range</code> <code>Iterator</code> (the '2018 version') could be <code>std::iter::Range</code>, since it's an iterator.</p>



<a name="228515908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Edition-dependent%20type%20aliases/near/228515908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Edition-dependent.20type.20aliases.html#228515908">(Mar 03 2021 at 01:00)</a>:</h4>
<p>This is messy if you have any <code>Range</code> in your public API too -- need to keep the old flavor to avoid a breaking change</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>